package com.ciaojian.store.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ciaojian.core.model.StoreCost;
import com.ciaojian.core.model.StoreFirstCost;
import com.ciaojian.core.util.Result;
import com.ciaojian.store.service.StoreCostServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author Atlakyn
 */
@Api(tags = "门店成本")
@RestController
@RequestMapping("/cost")
public class StoreCostController {
    @Resource
    private StoreCostServiceImpl storeCostService;

    @ApiOperation(value = "开店成本", response = StoreFirstCost.class)
    @GetMapping("/cost-first")
    public Result firstCost(@NotNull(message = "门店Id") Integer storeId) {
        LambdaQueryWrapper<StoreFirstCost> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StoreFirstCost::getStoreId, storeId);
        return Result.ok(new StoreFirstCost().selectOne(lambdaQueryWrapper));
    }

    @ApiOperation("每月成本")
    @GetMapping("/cost-month")
    public Result costOfMonth(@NotNull(message = "门店Id") Integer storeId,
                              @RequestParam(defaultValue = "0") Integer pageNo,
                              @RequestParam(defaultValue = "6") Integer pageSize) {
        QueryWrapper<StoreCost> lambdaQueryWrapper = new QueryWrapper<>();
        lambdaQueryWrapper.lambda()
                .eq(StoreCost::getStoreId, storeId)
                .orderByDesc(StoreCost::getAddTime);
        return Result.ok(storeCostService.pageMaps(new Page<>(pageNo, pageSize), lambdaQueryWrapper));
    }


}